package com.link.base.base.appinfo.controller;

import com.link.base.base.appinfo.model.AppPushConfig;
import com.link.base.base.appinfo.service.AppPushConfigService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 移动推送参数-维护移动消息推送相关的参数 
 *
 * @author ouyangzhenqiang
 * @date 2019/07/17 14:25
 */
@Controller
@RequestMapping("/link/appPushConfig")
public class AppPushConfigController extends BasicController<AppPushConfig> {

    @Resource
    private AppPushConfigService appPushConfigService;

    @Override
    public BasicService<AppPushConfig> getBasicService() throws Exception {
        return appPushConfigService;
    }

    /**
     * 将推送参数写入缓存
     *
     * @author ouyangzhenqiang
     * @date 2019/07/17 14:31
     */
    @PostMapping(value = "/setAppPushConfig", produces = "application/json", name = "推送参数写入缓存")
    @ResponseBody
    public Map<String, Object> setAppPushConfig(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        LCLogger.info().withMessageKey("setAppPushConfig").withMessage("将推送参数写入缓存...").flush();
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            appPushConfigService.setAppPushConfig();
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.toString());
        }
        return result;
    }
}
